package com.xing.lei.happy.thrid.flh.sql.model;

import com.xing.lei.happy.thrid.flh.sql.utils.SqlUtils;

public class InsertStatement {
    private static final String[] idNames = {"ID","QXID"};
    private String idName;

    private String table;
    private String columns;
    private String values;

    public InsertStatement(String table, String columns, String values) {
        this.table = table;
        this.columns = columns;
        this.values = values;
    }

    public String getTable() {
        return table;
    }

    public String getColumns() {
        return columns;
    }

    public String getValues() {
        return values;
    }
    public String getIdName() {
        return idName;
    }

    public String getId() {
        String[] cols = columns.split(",");
        String[] vals = SqlUtils.splitValues(values);
        for (String idName : idNames) {
            for (int i = 0; i < cols.length; i++) {
                if (cols[i].trim().equalsIgnoreCase(idName)) {
                    this.idName = idName;
                    return vals[i].trim().replaceAll("'", "");
                }
            }
        }
        if (cols.length > 0) {
            this.idName = cols[0];
            return vals[0].trim().replaceAll("'", "");
        }
        throw new IllegalArgumentException("未找到主键列: " + columns);
    }

    public void setTableName(String group) {
        throw new UnsupportedOperationException("Unimplemented method 'setTableName'");
    }
} 